<form action="" method="post" enctype="multipart/form-data" id="form_submit" class="form_submit">
  {if $smarty.get.type eq "edit"}
  	<input type="hidden" name="type" value="editt" />
    <input type="hidden" name="id" value="{$smarty.get.pageid}" />
  {else}
  	<input type=hidden name="type" value="add" />
  {/if}
  
  <input type="hidden" name="parent" value="{$smarty.get.id}" />
  <div id="admin_tabs_main_content"> 
    <!-- TABS_NAME -->
    <ul>
      <li><a href="#General">Общие</a></li>
      <li><a href="#Form">Форма</a></li>
      <li><a href="#SEO">SEO</a></li>
      <li><a href="#Files">Файлы</a></li>
    </ul>
    <!-- END TABS_NAME --> 
    <!-- ОБЩИЕ -->
    <div id="dialog-form-alert"></div>
    <div id="General" style="width:730px;">  
      {if $smarty.get.type eq "edit"}
        <p class="position_name">Запись создана</p>
        <p class="position_input">{$Field.date_create}<input type="hidden" name="date_create" value="{$Field.date_create}" /></p>
        
        <p class="position_name">Запись обновлена</p>
        <p class="position_input">{$Field.date_update}</p>	
      {/if}    

      <p class="position_name">Активна</p>
      <p class="position_input"><input type="checkbox" class="mini-switch" name="show" value="1"{if $Field.show} checked="checked"{/if} /></p>         
              
      <p class="position_name">Название</p>
      <p class="position_input"><input type="text" name="name" value="{$Field.name}" class="name" style="width:670px"> <input type="checkbox" class="mini-switch" name="is_header" value="1"{if $Field.is_header} checked="checked"{/if} /></p>
      
      <p class="position_name">Системное имя</p>
      <p class="position_input"><input type="text" name="sys_name" value="{$Field.sys_name}" class="sys_name"></p>
      
      <p class="position_name">Текст</p>
      <p class="position_input"><textarea name="text" rows="5" class="elrte_wo">{$Field.text}</textarea></p>
      
      <p class="position_name">Текст после формы</p>
      <p class="position_input"><textarea name="text_after" rows="5" class="elrte_wo">{$Field.text_after}</textarea></p>  
    </div>    
    
    <div id="Form">    
      <div style="width:730px;">  
        <p class="position_name">Тема письма (Subject)</p>
        <p class="position_input"><input type="text" name="subject" value="{$Field.subject}"></p>
        <p class="position_name">Откуда (From)</p>
        <p class="position_input"><input type="text" name="from" style="width:100%;" value="{$Field.from}"></p>
        <p class="position_name">Откуда (FromName)</p>
        <p class="position_input"><input type="text" name="fromname" style="width:100%;" value="{$Field.fromname}"></p>
        <p class="position_name">E-mail &nbsp; <a href="#addEmail" class="addEmail butt_rad_grad_grey">Добавить поле</a></p>
        <div class="listEmail">
        {if $Field.email}
          {foreach $Field.email as $key => $val}
            <p class="position_input"><input type="text" name="email[]" style="width:250px;" value="{$val}"> 
            <a href="javascript:void(0);" class="delete_email"><img title="удалить" src="/templates/admin/img/icons/delete.png"></a></p>
          {/foreach}
        {/if}
        </div>
      </div>
      <!-- Конструктор полей --> 
      <a href="#addRows" class="addRows butt_rad_grad_grey" style="float:right;">Добавить поле</a>
      <p><strong>Конструктор полей</strong></p>
      <table class="nowraptable" cellspacing="0">
        <thead>
          <tr>
            <th width="210">Название поля</th>
            <th width="90">Тип</th>
            <th width="100%" class="innerFieldName">Списки</th>
            <th align="center" width="40">*</th>
            <th align="center" width="18">&times;</th>
          </tr>
        </thead>
        <tbody id="rowsInner">
        {if $Field.field}
            {foreach $Field.field as $key => $val name=field_i}
              <tr>
                <td><input type="text" name="field[{$smarty.foreach.field_i.index}][namefield]" style="width:200px;" value="{$val.namefield}" /></td>
                <td><select name="field[{$smarty.foreach.field_i.index}][typefield]">{foreach $FieldOpt as $k => $v}<option value="{$k}"{if $val.typefield eq $k} selected="selected"{/if}>{$v}</option>{/foreach}</select></td>
                <td>{if $val.fieldarray}<input type="text" name="field[{$smarty.foreach.field_i.index}][fieldarray]" style="width:97%;" value="{$val.fieldarray}" />{/if}</td>
                <td><input type="checkbox" class="mini-switch" name="field[{$smarty.foreach.field_i.index}][obfield]" value="1"{if $val.obfield} checked="checked"{/if} /></td>
                <td><a href="javascript:void(0);" class="delete_tr"><img title="удалить" src="/templates/admin/img/icons/delete.png"></a></td>
              </tr>
            {/foreach}
        {/if}
        </tbody>
      </table>
      <div style="width:730px;">
        <div id="info_table" class="ui-state-highlight ui-corner-all">
          <p><span class="ui-icon ui-icon-info" style="float:left;margin-right:0.3em;"></span> <strong>* - Обязательные для заполнения поля</strong></p>
        </div>
      </div>
      <!-- END Конструктор полей -->      
      
    </div>
    <div id="SEO" style="width:730px;">
      <p class="position_name">Title</p>
      <p class="position_input"><textarea name="title" id="textform1" rows="3">{$Field.title}</textarea><div id="charlimitinfo1"></div></p>
      
      <p class="position_name">Description</p>
      <p class="position_input"><textarea name="description" id="textform2" rows="3">{$Field.description}</textarea><div id="charlimitinfo2"></div></p>
      
      <p class="position_name">Keywords</p>
      <p class="position_input"><textarea name="keywords" id="textform3" rows="3">{$Field.keywords}</textarea><div id="charlimitinfo3"></div></p>
    </div>    
    <div id="Files">
      {$IMAGE}
    </div>
  </div>
  
  <div id="posbutton">
    <a href="javascript:void(0);" class="ui_wo_buttons but_primenit ui-state-default ui-corner-all"><span class="ui-icon ui-icon-refresh"></span>Применить</a> 
    <a href="javascript:void(0);" class="ui_wo_buttons but_save ui-state-default ui-corner-all"><span class="ui-icon ui-icon-disk"></span>Сохранить</a>
  </div>
</form>
<script type="text/javascript">
$(function()
{
	/* Добавление e-mail */
	$(".addEmail").live("click", function(){
		$(".listEmail").append("<p class=\"position_input\"><input type=\"text\" align=\"absbottom\" name=\"email[]\" style=\"width:250px;\"> <a href=\"javascript:void(0);\" class=\"delete_email\"><img title=\"удалить\" src=\"/templates/admin/img/icons/delete.png\"></a></p>");
		return false;
	});	
	/* Удаление e-mail */			
	$(".delete_email").live("click", function(){					
		if(confirm("Удалить E-mail?")) {
			$(this).parent().empty().remove();						
		}
	});
	/* Добавление строки формы */
	$(".addRows").live("click", function(){
		var size_tr = $("#rowsInner tr").size();
		$("#rowsInner").append('<tr>'+
			'<td><input type="text" name="field['+size_tr+'][namefield]" style="width:200px;" /></td>'+
			'<td><select name="field['+size_tr+'][typefield]">'+
				'<option value="text">Текстовое поле</option>'+
				'<option value="checkbox">Чекбокс</option>'+
				'<option value="select">Список</option>'+
				'<option value="textarea">Многострочное поле</option>'+
				'<option value="radio">Радио кнопка</option>'+
			'</select></td>'+
			'<td>&nbsp;</td>'+
			'<td><input type="checkbox" name="field['+size_tr+'][obfield]" value="1" /></td>'+
			'<td><a href="javascript:void(0);" class="delete_tr"><img title="удалить" src="/templates/admin/img/icons/delete.png" /></a></td>'+
		'</tr>');
		$(".nowraptable tbody tr:even").addClass("darktd");		
		
		return false;
	});	
	/* Вставка списка */			
	$("#rowsInner select").live("change", function(){
		var this_type = $(this).attr("value");
		var next_td_insert = $(this).parent().next();
		var size_tr = $("#rowsInner tr").size();
		if(
		  this_type == "checkbox" || 
		  this_type == "select" || 
		  this_type == "radio"
		) {
			$(next_td_insert).html('<input type="text" name="field['+(size_tr-1)+'][fieldarray]" style="width:97%;" />');
			$(".innerFieldName").html('Значения через знак "|"');
		} else {
			$(next_td_insert).empty();
			$(".innerFieldName").empty();
		}
	});	
	/* Удаление строки формы */			
	$(".delete_tr").live("click", function(){					
		if(confirm("Удалить поле формы?")) {
			$(this).parent().parent().empty();						
		}
		$(".nowraptable tbody tr:even").addClass("darktd");
	});	
	
	$(".name").GoogleTranslate("{$TABLE}", {$ID_ACTION});
	var eForm = $("#form_submit");
	$(".but_primenit").live("click", function(){
		eForm.attr("action", '?m=content&id={$smarty.get.id}&parent={$smarty.get.parent}&pageid={$ID_ACTION}&type=edit').submit();		
	});		
	$(".but_save").live("click", function(){
		eForm.attr("action", '?m=content&id={$smarty.get.id}&parent={$smarty.get.parent}').submit();
	});	
});
</script>